{% block content %}
{% load help %}
<style type="text/css">
	.gradebook-groups-ungrouped,
	.gradebook-groups-multigrouped
	{
		border: 2px solid gray;
	}
	.gradebook-groups-ungrouped th,
	.gradebook-groups-multigrouped th
	{
		border-bottom: 2px solid gray;
	}
	.gradebook-groups-ungrouped td,
	.gradebook-groups-multigrouped td
	{
		padding: 0px 5px;
	}
	.gradebook-groups table
	{
		text-align: left;
	}
	table.gradebook-groups-group-information
	{
		width: 1px;
		white-space: nowrap;
	}
	.gradebook-groups-buttons
	{
		white-space: nowrap;
	}
	.gradebook-groups-users
	{
		overflow: auto;
		list-style: none;
		width: 100%;
	}
	.gradebook-groups-users ul
	{
		padding-left: 0px;
	}
	
	.gradebook-groups-users td
	{
		white-space: nowrap;
		padding: 0px 10px;
	}
	.gradebook-groups-random,
	.gradebook-groups-copy
	{
		vertical-align: middle;
		border-top: 2px solid gray;
	}
	.gradebook-groups-users-last-column
	{
		width: 100%;
	}
</style>
<div class="gradebook-groups">
	<form action="." method="POST">{% csrf_token %}
	<h1>
		Group Assignments for {{Assignment.title}}
		<button type="submit" class="button smallbutton DeleteButton floatright" name="delete_all" id="delete_all" title="Delete all groups">X</button>
	</h1>
			{% get_admin_help_list for group as help_list %}
			{% if help_list %}
			<span class="popup_container floatright">
				<span class="popup_title"><a><img src="{{STATIC_URL}}images/help.png" height=32></a></span>
				<span class="left_over_popup">
					{% if help_list %}
					<p>{{'Questions related to Groups:'|spacify}}</p>
					<ul>
					{% for faq in help_list %}
							<li><a class="FAQ_Question" name="{{faq.question_link}}" href="{{faq.url}}" target="_blank">{{faq.question|spacify}}</a></li>
					{% endfor %}
					</ul>
					{% else %}
					<p>{{'There is no help yet for this'|spacify}}</p>
					{% endif %}
				</span>
			</span>
			{% endif %}
		<table class="gradebook-groups-group-information">
			<tr>
				{% if Ungrouped %}
					<td class="gradebook-groups-ungrouped">
						<table border=0 cellpadding=0 cellspacing=0>
							<tr><th colspan="2"><h3>Ungrouped Students</h3></th></tr>
							
							{% for user in Ungrouped %}
								{% cycle "<tr>" "" %}
								<td class="gradebook-groupes-ungrouped-student">{{user.last_name}}, {{user.first_name}}</td>
								{% cycle "" "</tr>"%}
							{% endfor %}
							<tr>
								<td colspan="100%" class="gradebook-groups-random">
									Randomly distribute the ungrouped students into <input type="text" id="id_random_groups" name="id_random_groups" size="10"></input> new groups
									<button type="submit" class="button SaveButton smallbutton" name="create_random_groups" id="create_random_groups">Create</button>
								</td>
							</tr>
							{% if GroupForms|length > 1 %}
							<tr>
								<td colspan="100%" class="gradebook-groups-random">
									Randomly distribute the ungrouped students into the existing groups (equalizing group size)
									<button type="submit" class="button SaveButton smallbutton" name="equalize_groups" id="equalize_groups">Equalize</button>
								</td>
							</tr>
							{% endif %}
							{% if CopyForm %}
							<tr>
								<td colspan="100%" class="gradebook-groups-copy">
									Copy groups from another assignment:
									{{CopyForm.assignment}}
									<button type="submit" class="button SaveButton smallbutton" name="copy_groups" id="copy_groups">Copy</button>
								</td>
							</tr>
							{% endif %}
						</table>
					</td>
				{% endif %}
				{% if Multigrouped %}
					<td class="gradebook-groups-multigrouped">
						<table border=0 cellpadding=0 cellspacing=0>
							<tr><th colspan="2"><h3>Students in Multiple Groups</h3></th></tr>
							{% for user,groups in Multigrouped.items %}
								{% cycle "<tr>" "" %}
									<td class="gradebook-groupes-multigrouped-student">
										{{user.last_name}}, {{user.first_name}}:
										{% for group in groups %}{{group.group_name}}{% if not forloop.last %}, {% endif %}{% endfor %}
									</td>
								{% cycle "" "</tr>" %}
							{% endfor %}
						</table>
					</td>
				{% endif %}
			</tr>
			</table>
			<table border=1>
			{% for form in GroupForms %}
				{% if forloop.first and not forloop.last %}<tr><th colspan="100%"><h3>Existing Groups</h3></th></tr>{% endif %}
				{% if forloop.last %}<tr><th colspan="100%"><h3>Create New Group</h3></th></tr>{% endif %}
				<tr>
					<td class="gradebook-groups-name">
						{% if not forloop.last %}<button type="submit" class="button smallbutton DeleteButton floatright" name="delete_group" id="delete_group" value="{{form.instance.id}}" title="Delete this group">x</button>{% endif %}
						Group {{forloop.counter}}
						{{form.group_name}}
						{% if not forloop.last %}
							{% for user in form.instance.users.all %}
								{{user.last_name}},&nbsp;{{user.first_name}}<br>
							{% endfor %}
						{% endif %}
					</td>
					<td class="gradebook-groups-users">
						{% if not forloop.last %}Change Members{% else %}New Group Members{% endif %}<br>
						<table>
							{{form.users}}
							<tr><td colspan="4"></td><td rowspan="100%" class="gradebook-groups-users-last-column">&nbsp;</td></tr>
						</table>
					</td>
				</tr>
			{% endfor %}
			<tr>
				<td class="gradebook-groups-buttons" colspan="100%">
					<button type="submit" class="button SaveButton floatleft" name="Save" value="SaveEdit" title="Save and Continue Editing">Save and Continue</button>
					<button type="submit" class="button SaveButton floatleft" name="Save" value="SaveReturn" title="Save and Return to Gradebook">Save and Return</button>
					<a class="button SaveButton floatleft" href="{% course_url management app='grades' command='manage' arguments=Assignment.category_slug|concat:"&&"|concat:Assignment.title_slug %}" title="Cancel and Return to Gradebook">Cancel</a>
				</td>
			</tr>
		</table>
	</form>
</div>
{% endblock content %}